package HashMapDemo.Demo1;

import java.util.HashMap;
import java.util.Map.Entry;

import javax.swing.text.html.HTMLDocument.Iterator;

import java.util.Set;

public class test {
    public static void main(String[] args){
        // 创建3个学生
        Student s1 = new Student("lisi",21);
        Student s2 = new Student("jds",29);
        Student s3 = new Student("jds",29);
        
        // 创建集合
        HashMap<Student,String> hs = new HashMap<>();

        // 添加元素
        hs.put(s1,"广东");
        hs.put(s2,"陕西");
        hs.put(s3,"实际上");
        Set<Entry<Student,String>> s = hs.entrySet();
        // 创建迭代器
        java.util.Iterator<Entry<Student,String>> it = s.iterator();
        // 遍历迭代器
        
        for (Entry<Student,String> s4 : s) {
            Student sy = s4.getKey();
            String ad = s4.getValue();
            System.out.println(sy.getName() + "的年龄为：" + sy.getAge() + "居住地为" + ad);
        }
    }
}
